<template >
  <div class="add_con_form tl" v-loading="loading">
    <el-dialog
      :close-on-click-modal="false"
      title="发送站内信"
      :modal-append-to-body="false"
      :visible.sync="visible"
      :show="show"
      :before-close="closeDialog"
      @close="$emit('update:show',false)"
      class="tl size_13"
      width="800px"
    >
      <el-form :model="data" :rules="dataYZ" ref="data" class="mar_top" label-width="120px">
        <el-form-item label="会员账号">
          <el-col :span="12">
            <el-input
              :rows="4"
              :placeholder="this.editUser"
              v-model="data.alipay"
              style="width:220px;"
              :disabled="true"
              clearable
            ></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="信息内容">
          <el-col :span="12">
            <el-input
              type="textarea"
              :rows="4"
              v-model="data.content"
              style="width:580px;"
              clearable
            ></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="链接">
          <el-col :span="12">
            <el-input v-model="data.links" autocomplete="off"></el-input>
          </el-col>
          <el-col :span="5" :offset="1">
            <LinkMenu @sendRow="getSendRow"></LinkMenu>
          </el-col>
        </el-form-item>
        
        <el-form-item>
          <el-button
            :loading="$store.state.isLoading"
            size="medium"
            type="primary"
            @click.prevent="addUpdate('data')"
          >确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>


<style lang="less" scoped></style>

<script>
import LinkMenu from "@/components/currency/Link_menu.vue";
export default {
  data() {
    return {
      value: "",
      data: {
        id: "",
        content: "",
        links: ""
      },
      loading: false,
      dataYZ: {},
      visible: this.show
    };
  },
  props: {
    show: Boolean,
    editId: String,
    editUser: String,
    clickNum: Number
  },
  components: {
    LinkMenu
  },
  methods: {
    getSendRow(row) {
      console.log(row);
      if (row == null) return false;
      this.$store.dispatch("getShopsAll", { page: 1, page_size: 10 });
      if (row == null) return false;
      if (!row.disable && row.title == "自定义链接") {
        this.data.links = "";

        return false;
      }

      if (row.url) {
        this.data.links = row.url;
      }

      if (row.url_title == "产品分类" && row.click_title == "供应商分类") {
        this.data.links = "/pages/shop/supplier/supplier?cate=" + row.id;
        return;
      }
      if (row.url_title == "产品分类" && row.click_title != "供应商分类") {
        this.data.links = "/shop/shopsearch?cate_id=" + row.id;
      }
      if (row.url_title == "旅游产品分类") {
        this.data.links = "/tourshop/cate?cate_id=" + row.id;
      }
      if (row.url_title == "插件管理") {
        this.data.links = row.url || "";
      }

      if (row.url_title == "商品选择") {
        this.data.links = "/pages/shop/shopdetail/shopdetail?id=" + row.id;
      }
      if (row.url_title == "文章添加") {
        this.data.links = "/pages/news/newsdetail/newsdetail?id=" + row.id;
      }
      if (row.url_title == "资讯分类") {
        this.data.links = "/news?cate_id=" + row.id;
      }
    },
    closeDialog() {
      this.visible = false;
    },
    addUpdate(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          var params = {};
          params["id"] = this.data.id;
          params["content"] = this.data.content;
          params["links"] = this.data.links;
          params["username"] = this.editUser;
          this.$api.getUser.letterSaveAdd(params).then(res => {
            if (res.data.code == 200 && res.data.result != null) {
              this.$emit("parent", "这里刷新父页面");
              this.$fnc.alertSuccess({ text: "编辑成功" }); //成功弹出框
              this.visible = false;
            } else {
              this.$fnc.alertError(res.data.result); //失败弹出框
            }
          });
        }
      });
    }
  },
  watch: {
    show() {
      console.log(this.show);
      this.visible = this.show;
    },
    clickNum(id) {
      this.data.id = this.editId;

      this.data.content = "";
      console.log("点击button次数", id);
      console.log("编辑ID=" + this.editId);
      console.log("会员名:", this.editUser);
    }
  },
  mounted() {},
  created() {}
};
</script>
